package com.hsj.busmanager.job;

import com.hsj.busmanager.api.Position;
import com.hsj.busmanager.api.Status;
import com.hsj.busmanager.mapper.StatusMapper;
import com.hsj.busmanager.service.PositionSerivce;
import com.hsj.busmanager.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class PositionJob {

    @Autowired
    private PositionSerivce positionSerivce;

    @Autowired
    private StatusMapper statusMapper;

    /**
     * 每十秒执行一次，1、修改车辆经纬度并保存上次经度 2、计算两次经纬度之间的距离并更新车辆本月行驶距离
     */
//    @Scheduled(cron="0/10 * * * * ? ")
    public void setDistance() throws Exception{

        while (true){

            Thread.sleep(10000);

            //查询是否开启模拟定位
            Status status = statusMapper.selectByPrimaryKey(1);

            if(status.getOpen() == 1){
                //开启

                List<Position> positionList = positionSerivce.getPositionList();

                for(Position position:positionList){
                    //1、修改车辆经纬度并保存上次经度 2、计算两次经纬度之间的距离并更新车辆本月行驶距离
                    positionSerivce.handle(position);
                }

            }else{
                break;
            }




        }



    }
}
